//
//  OAWebShowViewController.m
//  LongOA
//
//  Created by XuJiuming on 15/9/28.
//  Copyright (c) 2015年 梁文朗. All rights reserved.
//

#import "OAWebShowViewController.h"

@interface OAWebShowViewController ()

@end

@implementation OAWebShowViewController
@synthesize fileName;
@synthesize myTitle;
@synthesize fileExt;
@synthesize fileRealName;
@synthesize fileID;

- (void)leftBarClicked:(id)sender {
    //[self.navigationController popViewControllerAnimated:NO];
    [self dismissViewControllerAnimated:NO completion:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createNavWithTitle:myTitle createMenuItem:^UIView *(int nIndex)
     {
         float btnwidth=40.0f;
         float btnheight=40.0f;
         if (nIndex ==0)
         {
             UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
             [btn setFrame:CGRectMake(10.0f, 20.0f+(self.navView.height-20 - 40)/2, btnwidth, btnheight)];
             [btn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
             [btn addTarget:self action:@selector(leftBarClicked:) forControlEvents:UIControlEventTouchUpInside];
             btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
             return btn;
         }
         
         return nil;
     }];
    /*
    NSString* fileAddress=nil;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    fileAddress=[path stringByAppendingPathComponent:fileName];
   
    NSString *tmpDir = NSTemporaryDirectory();
    //tmpDir=[[tmpDir stringByAppendingPathComponent:@"temp"] stringByAppendingPathExtension:fileExt];
    tmpDir=[[tmpDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%i",fileID]] stringByAppendingPathExtension:fileExt];
    
    NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    BOOL isDir;
    if ([fileMgr fileExistsAtPath:tmpDir isDirectory:&isDir]) {
        [fileMgr removeItemAtPath:tmpDir error:&error];
    }

    if ([fileMgr copyItemAtPath:fileAddress toPath:tmpDir error:&error] != YES)
        NSLog(@"Unable to move file: %@", [error localizedDescription]);
    */
    
    //[fileMgr copyItemAtPath:fileAddress toPath:tmpDir error:&error]
    
    
    //NSURLRequest* request=[NSURLRequest requestWithURL:[NSURL URLWithString:tmpDir]];
    NSURLRequest* request=[NSURLRequest requestWithURL:[NSURL URLWithString:fileName]];
    
    UIWebView* _protWebView=[[UIWebView alloc]initWithFrame:CGRectMake(0, self.navView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-self.navView.bottom)];
    _protWebView.scrollView.bounces=NO;
    [_protWebView setBackgroundColor:[UIColor clearColor]];
    //_protWebView.delegate=self;
    [self.view addSubview:_protWebView];
    _protWebView.scalesPageToFit=YES;
    [_protWebView loadRequest:request];
}
/*
- (void)webViewDidFinishLoad:(UIWebView *)web{
//    被调用之后，再延迟0.2秒以上调用以下函数：
//    然后即可获取整个网页的高度：
//    如果没有延迟，取出来的值是其frame的高度，增加延迟为了等待其加载页面渲染结束。
    float height = web.scrollView.contentSize.height;
    NSLog(@"height=%f",height);
    [self performSelector:@selector(delaySetting:) withObject:web afterDelay:0.2];
}
- (void)delaySetting:(UIWebView*)web {
    [web sizeToFit];
    float height = web.scrollView.contentSize.height;
    NSLog(@"height=%f",height);
}
*/
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
